import sys
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options


if __name__ == '__main__':
    keyword = '模特'
    if len(sys.argv) > 1:
        keyword = sys.argv[1]

    # 设置将浏览器隐藏打开
    op = Options()
    op.add_argument('--headless')

    driver = webdriver.Chrome(chrome_options=op)
    driver.get('https://image.baidu.com/')

    # 获取输入框
    kw = driver.find_element_by_id('kw')
    # 将keyword信息输入
    kw.send_keys(keyword)
    # 回车
    kw.send_keys(Keys.RETURN)

    # 等页面加载
    time.sleep(3)

    # 获取所有的图片节点
    products = driver.find_elements_by_class_name('imgbox')

    for p in products:
        img = p.find_element_by_xpath('.//img')

        print(img.get_attribute('data-imgurl'))

